#include "stdafx.h"
#include "GameMain.h"

int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPTSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.
	GameMain *gm = new GameMain(hInstance);
	// Initialize global strings
	// Perform application initialization:


	// Main message loop:

}
GameMain::GameMain(HINSTANCE hinst)
{
	RECT desktop;
	// Get a handle to the desktop window
	const HWND hDesktop = GetDesktopWindow();
	// Get the size of screen to the variable desktop
	GetWindowRect(hDesktop, &desktop);
	// The top left corner will have coordinates (0,0)
	// and the bottom right corner will have coordinates
	// (horizontal, vertical)
	int horizontal = desktop.right;
	int vertical = desktop.bottom;
	//Create window, with sizes from getwindowrect
	window = new Window(hinst);
	hwnd = window->Create(horizontal, vertical);
	//Maximize the window
	window->Maximize();
	
	g = new GraphicsEngine(hwnd);
	GameMap* m = new GameMap("heightmap.bmp");
	RECT* maprect = m->getMapSize();
	s = new Sun(horizontal,vertical,maprect->right,maprect->bottom);
	v = new Viewer(horizontal,vertical,maprect->right,maprect->bottom, m);
	
	g->setViewer(v);
	g->addLightSource(s);
	g->addDrawable(s);
	g->addDrawable(m);
	window->RegisterMessageHandler(WM_PAINT, g);
	window->RegisterMessageHandler(WM_MOUSEWHEEL, v);
	window->RegisterMessageHandler(WM_MOUSEMOVE, v);
	window->RegisterMessageHandler(WM_KEYDOWN, v);
	window->RegisterMessageHandler(WM_KEYUP, v);
    while(true)
    {
      if(!window->HandleMessages())
        break;
    }

}


GameMain::~GameMain(void)
{
}
